package io.yizoo.business.controller;

import io.elm.core.CoreController;
import io.yizoo.business.entity.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.EnumSet;
import java.util.List;

@RestController
@RequestMapping("/business/jxc/goods/out")
public class jxc_goods_outController extends CoreController {

    @Override
    protected void Init() {
        PowerEntity = biz_jxc_goods_out.class;
        PowerUse = EnumSet.of(Power.IDDelete, Power.IDAny, Power.IDGetSingle,Power.IDUpsert);
    }

    @PostMapping("/GetData")
    public Object GetData(@RequestBody String jsonStr) {
        List<?> ret = Ctor.CoreMapper.USelect(
                Ctor.DMaker(jsonStr).Selector
                        .Select("t.*,ifnull(a.name,t.dict) as dict_mc,ifnull(b.name,t.create_person) as create_person_mc," +
                                "ifnull(c.name,t.out_person) as out_person_mc,a.unit")
                        .From(biz_jxc_goods_out.class,"t")
                        .LeftJoin(biz_jxc_goods_dict.class,"a","a.id=t.dict")
                        .LeftJoin(biz_hrm_ei_basic.class,"b","b.emp_code=t.create_person")
                        .LeftJoin(biz_hrm_ei_basic.class,"c","c.emp_code=t.out_person")
                        .IsWhere("and t.name like concat('%', #{name}, '%')", "name")
                        .IsWhere("and t.dict = #{dict}", "dict")
                        .IsWhere("and t.create_time >= #{startDate}", "startDate")
                        .IsWhere("and t.create_time <= CONCAT(#{endDate},' 23:59:59')", "endDate")
                        .OrderBy("t.create_time desc")
                        .IsPage()
                        .GetFactor());
        return JsonResultPage(ret);
    }

}